﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data.SqlClient;
using BestLifePOS_Core.DomainObjects;
using BestLifePOS_Core.Data.Core;
using BestLifePOS_Core.Exceptions.DataBase;
using System.Data;

namespace BestLifePOS_Core.Data.Commands
{
    class BestLifeInsertVendorPaymentsDataAction : BestLifeDataAction<int>
    {

         private Vendor_Bill GvVendorPay;
         public BestLifeInsertVendorPaymentsDataAction(Vendor_Bill PVendorPay)
        {
            GvVendorPay = PVendorPay;
        }

        public override int Body(SqlConnection PConn)
        {
            try
            {
                SqlCommand LvCommand = new SqlCommand();
                LvCommand.Connection = PConn;
                LvCommand.CommandType = CommandType.StoredProcedure;
                LvCommand.CommandText = "dbo.InsertVendorPay";

                
                LvCommand.Parameters.Add(new SqlParameter("@SB_No", GvVendorPay.SB_No.ToString()));
                LvCommand.Parameters.Add(new SqlParameter("@Ven_No", GvVendorPay.Ven_No.ToString()));
                LvCommand.Parameters.Add(new SqlParameter("@Ven_Date", DateTime.Parse(GvVendorPay.Ven_date.ToString())));
                LvCommand.Parameters.Add(new SqlParameter("@Total", decimal.Parse(GvVendorPay.Total.ToString())));
                LvCommand.Parameters.Add(new SqlParameter("@PoId", GvVendorPay.Po_Id.ToString()));

                LvCommand.Parameters.Add(new SqlParameter("@User_Id", GvVendorPay.User_Id.ToString()));
                LvCommand.Parameters.Add(new SqlParameter("@Date_Create", DateTime.Parse(GvVendorPay.Date_Create.ToString())));
                LvCommand.Parameters.Add(new SqlParameter("@Last_Modify", DateTime.Parse(GvVendorPay.Last_Modify.ToString())));
                LvCommand.Parameters.Add(new SqlParameter("@User_Modify", GvVendorPay.User_Modify.ToString()));




                int LvCount = LvCommand.ExecuteNonQuery();
                return LvCount; 

            }
            catch (BestlifeDatabaseException e)
            {
                throw new BestlifeDatabaseException(e);
            }
        }
    }
}
